﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using TiTi.tea.Api.Models;
using TiTi.tea.BLL;
using TiTi.tea.Model;

namespace TiTi.tea.Api.Controllers
{
    [RoutePrefix("api/sku")]
    public class SkuController : ApiController
    {
        private SkuBLL bll = new SkuBLL();

        /// <summary>
        /// 根据spuId获取sku
        /// </summary>
        /// <param name="spuId"></param>
        /// <returns></returns>
        [Route("GetBySpec")]
        [HttpGet]
        public Result GetBySpec(int spuId,string specStr)
        {
            var data = bll.GetBySpec(spuId,specStr);
            return Result.Success(data);
        }

        /// <summary>
        /// 根据spuId获取sku
        /// </summary>
        /// <param name="spuId"></param>
        /// <returns></returns>
        [Route("GetBySpuId")]
        [HttpGet]
        public Result GetBySpuId(int spuId)
        {
            var data = bll.GetBySpuId(spuId);
            return Result.Success(data);
        }

        /// <summary>
        /// 根据id获取
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [Route("GetById")]
        [HttpGet]
        public Result GetById(int id)
        {
            return Result.Success(bll.GetById(id));
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="sku"></param>
        /// <returns></returns>
        [Route("Update")]
        [HttpPost]
        public Result Update(Sku sku)
        {
            return Result.Success(bll.Update(sku));
        }
    }
}